home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / ixnet / ixnet_open.c < prev    next >
C/C++ Source or Header  |  1996-03-13  |  4KB  |  140 lines

  1. /*
  2.  *  This file is part of ixnet.library for the Amiga.
  3.  *  Copyright (C) 1996 Jeff Shepherd
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  $Id:$
  20.  *
  21.  *  $Log:$
  22.  */
  23.  
  24. #define KERNEL
  25. #include "ixnet.h"
  26. #include "kprintf.h"
  27.  
  28. #include <amitcp/socketbasetags.h>
  29. #include <amitcp/usergroup.h>
  30. #include <exec/memory.h>
  31. #include <string.h>
  32. #include "ixprotos.h"
  33.  
  34. extern struct ixemul_base *ixemulbase;
  35.  
  36. struct ixnet_base *
  37. ixnet_open (struct ixnet_base *ixbase) {
  38.     struct ixnet *p;
  39.     struct Task *me;
  40.     struct user *ix_u;
  41.     struct ix_settings *settings; /* don't call this *ix there is a macro called ix!!! */
  42.     int network_type;
  43.  
  44.     me = SysBase->ThisTask;
  45.     ix_u = (struct user *)me->tc_TrapData; /* already initialized by ixemul.library */
  46.  
  47.     /* need this here instead of ixnet_init.c */
  48.     if (!ixemulbase)
  49.     ixemulbase = ix_u->u_ixbase;
  50.  
  51.     p = ix_u->u_ixnet = (struct ixnet *)AllocMem(sizeof(struct ixnet),MEMF_PUBLIC|MEMF_CLEAR);
  52.  
  53.     settings = ix_get_settings();
  54.     network_type = settings->network_type;
  55.  
  56.     if (p) {
  57.  
  58.       p->u_networkprotocol = IX_NETWORK_NONE;
  59.       switch (network_type) {
  60.  
  61.     case IX_NETWORK_AUTO:
  62.     case IX_NETWORK_AMITCP:
  63.         p->u_TCPBase = OpenLibrary ("bsdsocket.library",3);
  64.  
  65.         if (p->u_TCPBase) {
  66.         struct Process *thisproc = (struct Process *)me;
  67.         struct CommandLineInterface *cli = BTOCPTR(thisproc->pr_CLI);
  68.         char *progname = ((!thisproc->pr_CLI) ? me->tc_Node.ln_Name : BTOCPTR(cli->cli_CommandName));
  69.         struct TagItem list[] = {
  70.             { SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(int))), (ULONG)&u.u_errno }, /* dummy for now */
  71.             { SBTM_SETVAL(SBTC_HERRNOLONGPTR), (ULONG)&p->u_h_errno },
  72.             { SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG)progname },
  73.             { SBTM_SETVAL(SBTC_SIGIOMASK), NULL },
  74.             { SBTM_SETVAL(SBTC_SIGURGMASK), NULL },
  75.             { SBTM_SETVAL(SBTC_BREAKMASK), SIGBREAKF_CTRL_C },
  76.             { TAG_END }
  77.         };
  78.  
  79.         p->u_sigurg     = AllocSignal (-1);
  80.         p->u_sigio     = AllocSignal (-1);
  81.  
  82.         list[3].ti_Data = (1L << p->u_sigio);
  83.         list[4].ti_Data = (1L << p->u_sigurg);
  84.  
  85.         /* I will assume this always is successful */
  86.         TCP_SocketBaseTagList(p->u_TCPBase,list);
  87.  
  88.         /* only use usergroup stuff when AmiTCP is started only */
  89.         /* I call OpenLibrary() with the full path since
  90.          * usergroup.library might open yet - some people bypass the
  91.          * "login" command which loads usergroup.library
  92.          */
  93.         p->u_UserGroupBase = OpenLibrary("AmiTCP:libs/usergroup.library",1);
  94.  
  95.         if (p->u_UserGroupBase) {
  96.             struct TagItem ug_list[] = {
  97.             { UGT_INTRMASK, SIGBREAKB_CTRL_C } ,
  98.             { UGT_ERRNOPTR(sizeof(int)), (ULONG)u.u_errno },
  99.             { TAG_END }
  100.             };
  101.             ug_SetupContextTagList(p->u_UserGroupBase, progname, ug_list);
  102.             p->u_networkprotocol = IX_NETWORK_AMITCP;
  103.             break;
  104.         }
  105.         FreeSignal(p->u_sigurg);
  106.         FreeSignal(p->u_sigio);
  107.         CloseLibrary(p->u_TCPBase);
  108.         }
  109.         /* don't fall through if not auto-detect */
  110.         if (network_type != IX_NETWORK_AUTO)
  111.         break;
  112.  
  113.     /* falls through if something failed above */
  114.     case IX_NETWORK_AS225:
  115.         p->u_SockBase = OpenLibrary("socket.library",3);
  116.  
  117.         if (p->u_SockBase) {
  118.         p->u_sigurg     = AllocSignal (-1);
  119.         p->u_sigio     = AllocSignal (-1);
  120.         p->u_networkprotocol = IX_NETWORK_AS225;
  121.          }
  122.         break;
  123.     }
  124.  
  125.     if (p->u_networkprotocol == IX_NETWORK_NONE) {
  126.         extern struct ixnet_base *ixnetbase;
  127.         FreeMem(ix_u->u_ixnet,sizeof(struct ixnet));
  128.         /* decrement the open count since no network libraries installed */
  129.         /* so we keep the correct open count */
  130.         ixnetbase->ixnet_lib.lib_OpenCnt--;
  131.         return 0;
  132.     }
  133.     return ixbase;
  134.     }
  135.     ixnetbase->ixnet_lib.lib_OpenCnt--;
  136.     return 0;
  137. }
  138.  
  139.  
  140.